import { createRouter, createWebHistory } from 'vue-router'

const routes = [
  {
    path: '/',
    redirect: '/dashboard'
  },
  {
    path: '/dashboard',
    name: 'Dashboard',
    component: () => import('../views/Dashboard.vue'),
    meta: { title: '仪表盘' }
  },
  {
    path: '/statistics',
    name: 'Statistics',
    redirect: '/statistics/asset-overview',
    meta: { title: '统计分析' },
    children: [
      {
        path: 'asset-overview',
        name: 'AssetOverview',
        component: () => import('../views/statistics/AssetOverview.vue'),
        meta: { title: '资产概览' }
      },
      {
        path: 'status-distribution',
        name: 'StatusDistribution',
        component: () => import('../views/statistics/StatusDistribution.vue'),
        meta: { title: '状态分布' }
      },
      {
        path: 'dept-distribution',
        name: 'DeptDistribution',
        component: () => import('../views/statistics/DeptDistribution.vue'),
        meta: { title: '部门分布' }
      },
      {
        path: 'asset-ledger',
        name: 'AssetLedger',
        component: () => import('../views/statistics/AssetLedger.vue'),
        meta: { title: '资产台账' }
      },
      {
        path: 'asset-transfer',
        name: 'AssetTransfer',
        component: () => import('../views/statistics/AssetTransfer.vue'),
        meta: { title: '资产流转报表' }
      },
      {
        path: 'dept-heat',
        name: 'DeptHeat',
        component: () => import('../views/statistics/DeptHeat.vue'),
        meta: { title: '部门领用热度' }
      }
    ]
  },
  {
    path: '/check',
    name: 'Check',
    redirect: '/check/plan',
    meta: { title: '资产盘点' },
    children: [
      {
        path: 'plan',
        name: 'CheckPlan',
        component: () => import('../views/check/CheckPlan.vue'),
        meta: { title: '盘点计划' }
      },
      {
        path: 'plan-settings',
        name: 'CheckPlanSettings',
        component: () => import('../views/check/CheckPlanSettings.vue'),
        meta: { title: '盘点计划设置' }
      },
      {
        path: 'task',
        name: 'CheckTask',
        component: () => import('../views/check/CheckTask.vue'),
        meta: { title: '盘点任务' }
      },
      {
        path: 'report',
        name: 'CheckReport',
        component: () => import('../views/check/CheckReport.vue'),
        meta: { title: '盘点记录报表' }
      },
      {
        path: 'statistics',
        name: 'CheckStatistics',
        component: () => import('../views/check/CheckStatistics.vue'),
        meta: { title: '盘点统计分析' }
      },
      {
        path: 'diff-list',
        name: 'DiffList',
        component: () => import('../views/check/DiffList.vue'),
        meta: { title: '盘点差异列表' }
      }
    ]
  }
]

const router = createRouter({
  history: createWebHistory(),
  routes
})

router.beforeEach((to, from, next) => {
  document.title = to.meta.title ? `${to.meta.title} - 小微资产管理系统` : '小微资产管理系统'
  next()
})

export default router